package 多线程;

/**
 * @ClassName: Demo1
 * @Auther: Drawin
 * @Date: 2021/11/10 16:03
 * @Description:多线程作业之11-1
 */

//继承Thread类
public class Demo1 extends Thread {
    private String name;//the name of a thread
    public Demo1(String name){
        super(name);
        System.out.println(name+"创建成功");
    }
    public void run(){
        for(int i=0;i<3;i++){
            System.out.println(Thread.currentThread().getName()+"第"+i+"次运行");
            Thread.yield();//让当前线程让出CPU
        }
    }

    public static void main(String[] args) {
        Demo1 t1=new Demo1("第一个线程");
        Demo1 t2=new Demo1("第二个线程");
        System.out.println("开始启动t1,t2线程");
        t1.start();//t1开始独立运行
        t2.start();//同上
        System.out.println("main方法运行完毕");
    }
}
